/*
package triIndex.btree;

import java.util.*;
import triStorage.*;

public class BLeaf extends BNode {

	int nextNodeId = 0;

	public BLeaf(int order, NodeFactory factory) {
		this.order = order;
		this.leastChildNum = (order + 1) / 2;
		this.factory = factory;
	}

	public BLeaf(int order, int nodeId, int nextNodeId, NodeFactory factory) {
		this.order = order;
		this.leastChildNum = (order + 1) / 2;
		this.keys = new Vector<Integer>();
		this.values = new Vector<Integer>();
		this.nodeId = nodeId;
		this.nextNodeId = nextNodeId;
		this.factory = factory;
	}

	@Override
	public int find(int key) {
		for (int i = 0; i < childnum; ++i)
			if (key < keys.get(i))
				return BTree.ERROR_CODE;
			else if (key == keys.get(i))
				return values.get(i);
		
		return BTree.ERROR_CODE;
	}

	@Override
	public BNode[] insert(int key, int value) {
		int index;
		for (index = 0; index < childnum; ++index)
			if (key < keys.get(index))
				break;
		keys.add(index, key);
		values.add(index, value);
		childnum++;
		BNode[] ret;
		
		if (childnum > order)
			ret = split();
		else {
			ret = new BNode[1];
			ret[0] = this;
		}
		
		return ret;
	}

	private BNode[] split() {
		BLeaf leaf = factory.createNewLeaf(this.order, this.nextNodeId);
				//new BLeaf(this.order, nextNodeId, factory);
		nextNodeId = leaf.nodeId;

		for (int i = leastChildNum; i < childnum; ++i) {
			leaf.keys.add(keys.remove(leastChildNum));
			leaf.values.add(values.remove(leastChildNum));
		}
		leaf.childnum = childnum - leastChildNum;
		childnum = leastChildNum;
		
		BNode[] ret = new BNode[2];
		ret[0] = this;
		ret[1] = leaf;
		return ret;
	}

	@Override
	public void flush(IWriter writer) {
		writer.appendInt(nodeId);
		writer.appendInt(BNode.LEAF);
		writer.appendInt(nextNodeId);
		writer.appendInt(childnum);
		
		for (int i = 0; i < childnum; ++i) {
			writer.appendInt(keys.get(i));
			writer.appendInt(values.get(i));
		}
	}

	@Override
	public void load(IReader reader) {
		this.nodeId = reader.readInt();
		if (reader.readInt() != BNode.LEAF)
			System.err.println("node " + nodeId + "is not leaf!");
		childnum = reader.readInt();
		this.keys = new Vector<Integer>(childnum);
		this.values = new Vector<Integer>(childnum);
		for (int i = 0; i < childnum; ++i) {
			keys.add(reader.readInt());
			values.add(reader.readInt());
		}
		
	}

	public void outputSelf(String s) {
		System.out.println(s + "------Bleaf-----");
		for (int i = 0 ; i < childnum ; ++i)
			System.out.println(s + "child " + i + " : " + keys.get(i).toString() + ","+
					values.get(i));
		System.out.println(s + "-----Bleaf over---- " + nextNodeId);
	}
}
*/